/**
 * File Name   : DiscountTypeService.java
 * Description : 
 */
package com.hh.admin.discounttype.service;

import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.hh.admin.discounttype.form.DiscountTypeBean;
import com.hh.admin.discounttype.form.DiscountTypeForm;
import com.hh.common.ibatis.dao.IQueryDao;
import com.hh.common.ibatis.dao.IUpdateDao;

/**
 * 消费打折类型管理Service
 * @author 冯昌硕
 * @create 2013-3-10 上午12:54:18
 */
public class DiscountTypeService {

    private static final Logger log = Logger.getLogger(DiscountTypeService.class);

    private IQueryDao queryDao;
    
    private IUpdateDao updateDao;
    
    /**
     * 添加消费打折类型内容记录
     * @param form
     * @return
     * @throws SQLException
     * @create 2013-3-10 上午9:08:36
     */
    public int insertDiscounttype(DiscountTypeForm form) throws SQLException {
        DiscountTypeBean paramBean = new DiscountTypeBean();
        paramBean.setName(form.getName());
        paramBean.setCreateUser(form.getCreateUser());
        paramBean.setStatus(form.getStatus());
        
        log.debug("新增消费打折类型信息 paramBean=[" + paramBean + "]");
        return (Integer) updateDao.insert("discounttype.insertDiscounttype", paramBean);
    }
    
    /**
     * 根据主键查询内容详情
     * @param id
     * @return
     * @throws ClassCastException
     * @throws SQLException
     * @create 2013-3-10 上午9:19:08
     */
    public DiscountTypeBean getDiscountTypeDetail(int id) throws ClassCastException, SQLException {
        return queryDao.queryForObject("discounttype.selDiscountTypeDetail", id, DiscountTypeBean.class);
    }
    
    /**
     * 更新内容记录
     * @param form
     * @return
     * @throws SQLException
     * @create 2013-3-10 上午9:33:40
     */
    public int updateDiscountType(DiscountTypeForm form) throws SQLException {
        DiscountTypeBean paramBean = new DiscountTypeBean();
        paramBean.setId(form.getId());
        paramBean.setName(form.getName());
        paramBean.setStatus(form.getStatus());
        
        log.debug("更新消费打折类型信息 paramBean=[" + paramBean + "]");
        return updateDao.update("discounttype.updateDiscounttype", paramBean);
    }
    
    /**
     * 单条删除记录
     * @param id
     * @return
     * @throws SQLException
     * @create 2013-3-10 上午9:48:14
     */
    public int deleteOne(int id) throws SQLException {
        return updateDao.delete("discounttype.deleteDiscountType", id);
    }
    
    /**
     * 批量删除记录
     * @param ids
     * @return
     * @throws SQLException
     * @create 2013-3-10 上午9:51:15
     */
    public int deleteMany(Integer[] ids) throws SQLException {
        return updateDao.batchDelete("discounttype.deleteDiscountType", ids);
    }

    public void setQueryDao(IQueryDao queryDao) {
        this.queryDao = queryDao;
    }

    public void setUpdateDao(IUpdateDao updateDao) {
        this.updateDao = updateDao;
    }
    
}
